package com.atguigu.ssyx.acl.controller;

import com.atguigu.ssyx.acl.service.PermissionService;
import com.atguigu.ssyx.common.result.Result;
import com.atguigu.ssyx.model.acl.Permission;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/acl/permission")
@Api(tags ="菜单管理接口")
@CrossOrigin

public class PermissionController {

    @Autowired
    private PermissionService permissionService;
    @GetMapping
    @ApiOperation("获取权限(菜单/功能)列表")
    public Result request(){
        List<Permission> list = permissionService.queryAllMenu();
        return Result.ok(list);
    }


    @DeleteMapping("remove/{id}")
    @ApiOperation("删除一个权限项接口")
    public Result remove(@PathVariable Long id){
        permissionService.removeChildById(id);
        return Result.ok(null);
    }


    @PutMapping("update")
    @ApiOperation("更新一个权限项")
    public Result updateById(@RequestBody Permission permission) {
        permissionService.updateById(permission);
        return Result.ok(null);
    }



    @PostMapping("save")
    @ApiOperation("保存一个权限项")
    public Result save(@RequestBody Permission permission){
        permissionService.save(permission);
        return Result.ok(null);
    }





}
